//
//  ViewController.m
//  AFNworking
//
//  Created by 邹金金 on 16/8/18.
//  Copyright © 2016年 邹金金. All rights reserved.
//

#import "ViewController.h"
#import "AFNetworking.h"
@interface ViewController ()

@end

@implementation ViewController
static NSString *const urlPath=@"http://www.bilibili.com";

- (void)viewDidLoad {
    [super viewDidLoad];
    UIImageView *img=[[UIImageView alloc]initWithFrame:self.view.frame];
    img.image=[UIImage imageNamed:@"103.jpg"];
    [self.view addSubview:img];
    
    [self runMonitor];
    [self afnWangLuoQingQiu];
    
    // Do any additional setup after loading the view, typically from a nib.
}
- (void)runMonitor
{
    // 网络诊断，用来打印当前网络状态
    AFNetworkReachabilityManager *monitor=[AFNetworkReachabilityManager sharedManager];
    [monitor setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch (status) {
            case AFNetworkReachabilityStatusUnknown:
                NSLog(@"未知网络······");
                break;
            case AFNetworkReachabilityStatusReachableViaWiFi:
                NSLog(@"WIFIW网络······");
                break;
            case AFNetworkReachabilityStatusNotReachable:
                NSLog(@"断网了······");
                break;
            case AFNetworkReachabilityStatusReachableViaWWAN:
                NSLog(@"有线网络······");
                break;
            default:
                NSLog(@"未知状态");
                break;
        }
    }];
    [monitor startMonitoring];

}
- (void)afnWangLuoQingQiu
{
    // 开始测试AFN
    AFHTTPSessionManager *manager=[AFHTTPSessionManager manager];
    // 设置HTTP协议解析方式
    AFHTTPResponseSerializer *parser=[AFHTTPResponseSerializer serializer];
    parser.acceptableContentTypes=[NSSet setWithObjects:@"text/html", nil];
    manager.responseSerializer=parser;
    
    [manager GET:urlPath parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        NSString *string=[[NSString alloc]initWithData:responseObject encoding:NSUTF8StringEncoding];
        NSLog(@"成功----->,%@",string);
        }failure:^(NSURLSessionDataTask *task, NSError *error) {
            NSLog(@"失败----->,%@",error);
        }];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
